package com.wn.pettyloan.service.impl;

import com.wn.pettyloan.dto.UserDto;
import com.wn.pettyloan.entity.User;
import com.wn.pettyloan.mapper.UserMapper;
import com.wn.pettyloan.service.UserService;
import com.wn.pettyloan.vo.UserVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: pettyloan
 * @ClassName UserServiceImpl
 * @author: 韩旭
 * @create: 2022-12-06 14:29
 **/
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public User selectUserByUserName(String tel) {
        return userMapper.selectUserByUserName(tel);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(User record) {
        return userMapper.insert(record);
    }

    @Override
    public int insertSelective(User record) {



        return userMapper.insertSelective(record);
    }

    @Override
    public User selectByPrimaryKey(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }

    @Override
    public User login(UserDto userDto) {
        return userMapper.login(userDto);
    }

    @Override
    public UserVo selectSelf(UserDto userDto) {
        return userMapper.selectSelf(userDto);
    }

    @Override
    public int updateUserNameOrImg(UserDto userDto) {
        return userMapper.updateUserNameOrImg(userDto);
    }

    @Override
    public int insertUser(UserDto userDto) {
        UserVo userVo = userMapper.selectSelf(userDto);
        if (userVo != null) {
            return 0;
        } else {
            User user = new User();
            user.setUserImg(userDto.getUserImg());
            user.setUserName(userDto.getUserName());
            user.setUserState(1);//1为正常
            user.setUserPassword(userDto.getPassword());
            user.setUserTel(userDto.getTel());
            user.setRoleId(4);//4为普通用户
            user.setUserTagId(1);//1为潜力用户
            return userMapper.insert(user);
        }

    }
}